package com.zerox.springsecuritydemo329.controller;

import com.zerox.springsecuritydemo329.pojo.SysUser;
import com.zerox.springsecuritydemo329.service.SysUserService;
import com.zerox.springsecuritydemo329.utils.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
public class LoginController {

    @Autowired
    private SysUserService sysUserService;

    @PostMapping("/doLogin")
    public ResponseResult doLogin(SysUser sysUser){

       String token = sysUserService.login(sysUser);

        HashMap<String, String> map = new HashMap<>();
        map.put("token",token);

        ResponseResult responseResult = new ResponseResult<Map>(HttpStatus.OK.value(),"登录成功",map);

        return responseResult;
    }

    @PostMapping("/doLogout")
    public ResponseResult doLogout(){

        sysUserService.logout();

        ResponseResult responseResult = new ResponseResult<Map>(HttpStatus.OK.value(),"登出成功");

        return responseResult;
    }
}
